package qmlt.learning.bagging;

import qmlt.learning.Learner;

public class BaggingController<P, L extends Learner<P>>
{
    private Class<L> baggedLearnerClass;

    private P        params;

    private int      nReplicates;

    private int      replicateSizePercentage;

    public BaggingController(Class<L> baggedLearnerClass, P controller, int nReplicates,
            int replicateSizePercentage)
    {
        this.baggedLearnerClass = baggedLearnerClass;
        this.params = controller;
        this.nReplicates = nReplicates;
        this.replicateSizePercentage = replicateSizePercentage;
    }

    public Class<L> getBaggedLearnerClass()
    {
        return baggedLearnerClass;
    }

    public P getBaggedLearnerParams()
    {
        return params;
    }

    public L getBaggedLearnerInstance()
    {
        try
        {
            return baggedLearnerClass.newInstance();
        }
        catch (Exception e)
        {
            System.err.println("failed to create a learner instance: " + e.getMessage());
            e.printStackTrace();
            return null;
        }
    }

    public int getNReplicates()
    {
        return nReplicates;
    }

    public int getReplicateSizePercentage()
    {
        return replicateSizePercentage;
    }
}
